<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title> - tweener.coffee</title>

  <link rel="stylesheet" href="../../../assets/style.css">
  
    
      <style>
        
      </style>
    
  

  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"/>
  <meta name="groc-relative-root" content="../../../"/>
  <meta name="groc-document-path" content="../spec/tween/tweener.coffee"/>
  
</head>
<body>
  <div id="file-area">
    <div id="meta">
      <code class="file-path">
      
        <a href="https://github.com/legomushroom/mojs.git/blob/master/../spec/tween/tweener.coffee">../spec/tween/tweener.coffee</a>
      
      </code>
    </div>
    <div id="document">
    
      <div class="segment">
      
      
        <div class="code"><div class="wrapper">t        = <span class="hljs-built_in">window</span>.mojs.tweener
Tween    = <span class="hljs-built_in">window</span>.mojs.Tween
Timeline = <span class="hljs-built_in">window</span>.mojs.Timeline

describe <span class="hljs-string">'Twenner -&gt;'</span>, <span class="hljs-function">-&gt;</span>
  afterEach  -&gt; t.stopLoop(); t.tweens.length = <span class="hljs-number">0</span>
  beforeEach -&gt; t.stopLoop(); t.tweens.length = <span class="hljs-number">0</span>
  it <span class="hljs-string">'have tweens array'</span>, <span class="hljs-function">-&gt;</span>
    expect(t.tweens).toBeDefined()
    expect(t.tweens <span class="hljs-keyword">instanceof</span> Array).toBe <span class="hljs-literal">true</span>

  describe <span class="hljs-string">'polyfills -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should have performance now defined'</span>, <span class="hljs-function">-&gt;</span>
      expect(<span class="hljs-built_in">window</span>.performance.now).toBeDefined()
    it <span class="hljs-string">'should have requestAnimationFrame defined'</span>, <span class="hljs-function">-&gt;</span>
      expect(<span class="hljs-built_in">window</span>.requestAnimationFrame).toBeDefined()

  describe <span class="hljs-string">'loop -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should loop over'</span>, <span class="hljs-function"><span class="hljs-params">(dfr)</span>-&gt;</span>
      t.startLoop()
      t.add <span class="hljs-keyword">new</span> Tween
      spyOn t, <span class="hljs-string">'loop'</span>
      setTimeout -&gt;
        expect(t.<span class="hljs-keyword">loop</span>).toHaveBeenCalled(); dfr()
      , <span class="hljs-number">100</span>
    it <span class="hljs-string">'should call update fun'</span>, <span class="hljs-function"><span class="hljs-params">(dfr)</span>-&gt;</span>
      t.startLoop()
      spyOn t, <span class="hljs-string">'update'</span>
      setTimeout -&gt;
        expect(t.update).toHaveBeenCalledWith(jasmine.any(Number)); dfr()
      , <span class="hljs-number">100</span>
    it <span class="hljs-string">'should stop at the end'</span>, <span class="hljs-function"><span class="hljs-params">(dfr)</span>-&gt;</span>
      t.add <span class="hljs-keyword">new</span> Tween
      t.startLoop()
      setTimeout (<span class="hljs-function">-&gt;</span> t.tweens[<span class="hljs-number">0</span>].update = <span class="hljs-function">-&gt;</span> <span class="hljs-literal">true</span>), <span class="hljs-number">100</span>
      setTimeout (<span class="hljs-function">-&gt;</span> expect(t.isRunning).toBe(<span class="hljs-literal">false</span>); dfr()), <span class="hljs-number">200</span>
  describe <span class="hljs-string">'startLoop method -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should call loop method'</span>, <span class="hljs-function"><span class="hljs-params">(dfr)</span>-&gt;</span>
      spyOn t, <span class="hljs-string">'loop'</span>
      t.startLoop()
      setTimeout -&gt;
        expect(t.<span class="hljs-keyword">loop</span>).toHaveBeenCalled()
        dfr()
      , <span class="hljs-number">60</span>
    it <span class="hljs-string">'should set isRunning flag'</span>, <span class="hljs-function">-&gt;</span>
      expect(t.isRunning).toBeFalsy()
      t.startLoop()
      expect(t.isRunning).toBe <span class="hljs-literal">true</span>
    it <span class="hljs-string">'should call loop only once'</span>, <span class="hljs-function">-&gt;</span>
      t.startLoop()
      spyOn t, <span class="hljs-string">'loop'</span>
      t.startLoop()
      expect(t.<span class="hljs-keyword">loop</span>).<span class="hljs-keyword">not</span>.toHaveBeenCalled()
    it <span class="hljs-string">'should start only 1 concurrent loop'</span>, <span class="hljs-function"><span class="hljs-params">()</span>-&gt;</span>
      t.startLoop()
      expect(t.isRunning).toBe <span class="hljs-literal">true</span>
      spyOn <span class="hljs-built_in">window</span>, <span class="hljs-string">'requestAnimationFrame'</span>
      t.startLoop()
      expect(<span class="hljs-built_in">window</span>.requestAnimationFrame).<span class="hljs-keyword">not</span>.toHaveBeenCalled()
  describe <span class="hljs-string">'stopLoop method -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should set isRunning to false'</span>, <span class="hljs-function">-&gt;</span>
      t.startLoop()
      t.stopLoop()
      expect(t.isRunning).toBe <span class="hljs-literal">false</span>
  describe <span class="hljs-string">'add method -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should add to tweens'</span>, <span class="hljs-function">-&gt;</span>
      t.add <span class="hljs-keyword">new</span> Tween
      expect(t.tweens.length).toBe <span class="hljs-number">1</span>
      expect(t.tweens[<span class="hljs-number">0</span>] <span class="hljs-keyword">instanceof</span> Tween).toBe <span class="hljs-literal">true</span>
    it <span class="hljs-string">'should call startLoop method'</span>, <span class="hljs-function">-&gt;</span>
      spyOn t, <span class="hljs-string">'startLoop'</span>
      t.add <span class="hljs-keyword">new</span> Tween
      expect(t.startLoop).toHaveBeenCalled()
  describe <span class="hljs-string">'remove method -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should remove a tween'</span>, <span class="hljs-function">-&gt;</span>
      t1 = <span class="hljs-keyword">new</span> Tween; t2 = <span class="hljs-keyword">new</span> Tween
      t.add t1; t.add t2
      expect(t.tweens.length).toBe <span class="hljs-number">2</span>
      t.remove t2
      expect(t.tweens.length).toBe <span class="hljs-number">1</span>
    it <span class="hljs-string">'should be able to remove by i'</span>, <span class="hljs-function">-&gt;</span>
      t1 = <span class="hljs-keyword">new</span> Tween; t2 = <span class="hljs-keyword">new</span> Tween
      t.add t1; t.add t2
      expect(t.tweens.length).toBe <span class="hljs-number">2</span>
      t.remove <span class="hljs-number">1</span>
      expect(t.tweens.length).toBe <span class="hljs-number">1</span>
      expect(t.tweens[<span class="hljs-number">0</span>])    .toBe t1
  describe <span class="hljs-string">'removeAll method -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should remove all tweens'</span>, <span class="hljs-function">-&gt;</span>
      t1 = <span class="hljs-keyword">new</span> Tween; t2 = <span class="hljs-keyword">new</span> Tween
      t.add t1; t.add t2
      expect(t.tweens.length).toBe <span class="hljs-number">2</span>
      t.removeAll()
      expect(t.tweens.length).toBe <span class="hljs-number">0</span>

  describe <span class="hljs-string">'update method -&gt;'</span>, <span class="hljs-function">-&gt;</span>
    it <span class="hljs-string">'should update the current time on every timeline'</span>,<span class="hljs-function">-&gt;</span>
      t.add <span class="hljs-keyword">new</span> Tween
      t.add <span class="hljs-keyword">new</span> Tween
      spyOn t.tweens[<span class="hljs-number">0</span>], <span class="hljs-string">'update'</span>
      spyOn t.tweens[<span class="hljs-number">1</span>], <span class="hljs-string">'update'</span>
      t.update time = performance.now() + <span class="hljs-number">200</span>
      expect(t.tweens[<span class="hljs-number">0</span>].update).toHaveBeenCalledWith time
      expect(t.tweens[<span class="hljs-number">1</span>].update).toHaveBeenCalledWith time



</div></div>
      
      </div>
    
    </div>
  </div>

  <script src="../../../toc.js"></script>
  <script src="../../../assets/libs.js"></script>
  <script src="../../../assets/behavior.js"></script>

  
    
      <script>
        
      </script>
    
  
</body>
</html>